package by.shade.news;

import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;

/**
 * Single news item.
 *
 * @author homyakov
 * @version $Id: Item.java 5 2012-08-14 16:02:17Z vkhomyackov@gmail.com $
 */
public class Item {

    private String title;
    /** Short description. */
    private String description;
    /** Full content. */
    private String content;
    /** Link to web page. */
    private String link;
    private String author;
    private Calendar date;

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Calendar getDate() {
        return date;
    }

    public void setDate(Calendar date) {
        this.date = date;
    }

    public void setDate(Date date) {
        Calendar calendar = null;
        if (date != null) {
            calendar = Calendar.getInstance();
            calendar.setTime(date);
        }
        this.date = calendar;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = StringUtils.trimToEmpty(description).replaceAll("\\s+", " ");
    }

    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("Item [");
        if (title != null) {
            builder.append("title=").append(title).append(", ");
        }
        if (description != null) {
            builder.append("description=").append(description).append(", ");
        }
        if (content != null) {
            builder.append("content=").append(content).append(", ");
        }
        if (link != null) {
            builder.append("link=").append(link).append(", ");
        }
        if (author != null) {
            builder.append("author=").append(author).append(", ");
        }
        if (date != null) {
            builder.append("date=").append(DateFormatUtils.format(date, "dd-MM-yyyy HH:mm:ss"));
        }
        builder.append("]");
        return builder.toString();
    }

}
